<template>

  <div>
    <div class="header-Main" style="margin-top: 10px; margin-left: 5px;"> 
      <el-input v-model="username" placeholder="输入内容" suffix-icon="el-icon-search" style="width: 500px;"></el-input>
      <el-button type="primary" style="margin: 0 20px 0 5px;" @click="handlget">查询</el-button>
      <el-button type="primary">
        <div @click="add" style="color: aliceblue;">增加<i class="el-icon-circle-plus-outline iconadd" style="font-size: 15px;"></i></div>
        </el-button>
    </div>

    <div v-if="tableData != '' && tableData != null">
      <el-table ref="multipleTable" :data="tableData" tooltip-effect="dark" 
        border style="width: 100%">

        <el-table-column prop="id" label="ID" width="100">

        </el-table-column>

        <el-table-column prop="image" label="图片" width="140">
          <template slot-scope="scope">
            <div class="imagecontainer">
              <img :src="scope.row.image" style="height: 100%; width: 100%;">
            </div>
          </template>
        </el-table-column>

        <el-table-column prop="name" label="用户民" width="140">
          <template slot-scope="scope">{{ scope.row.username }}</template>
        </el-table-column>

        <el-table-column prop="name" label="密码" width="140">
          <template slot-scope="scope">{{ scope.row.password }}</template>
        </el-table-column>

        <el-table-column prop="address" label="地区" width="100">
          
        </el-table-column>

        <el-table-column prop="sex" label="性别" width="100">
          <template slot-scope="scope">
            <span v-if="scope.row.sex==1">男</span>
            <span v-else>女</span>
          </template>>
        </el-table-column>

        <el-table-column prop="introduce" label="签名">
          <template slot-scope="scope">
            <p style="height: 130px;overflow-y: scroll;">{{ scope.row.introduce}}</p>
          </template>
        </el-table-column>


        <el-table-column width="150" label="操作">
          <template slot-scope="scope">
            <el-button type="primary" icon="el-icon-edit"  circle @click="handlEditor(scope.row.id)"></el-button>
            <el-button type="danger" icon="el-icon-delete" circle @click="handlDelete(scope.row.id)"></el-button>
          </template>
        </el-table-column>

      </el-table>

      <div class="pageion"> 
        <pagination :total="total" :PageSize="PageSize" :PageNum="PageNum" 
          @ChangeSize="changesize" @ChangeNum="changenum"></pagination>
      </div>
    </div>
    <div v-else>

    </div>
  </div>

</template>

<script>
import pagination from '@/components/Pagination/index.vue'
import { mapMutations } from 'vuex'
export default {

  components:{
    pagination
  },
  created(){
    this.getAll()
  },
  data() {
      return {
        username:'',
        id: 1,
        tableData: [],
        total:10,
        PageSize:4,
        PageNum:1
      }
    },

    methods:{
      ...mapMutations('editfo',['changeTitle','changeDatas']),
      ...mapMutations('song1',['getSingerId']),
      async getAll(){
        const res =await this.$axios.post(`User/SelectAll?PageNum=${this.PageNum}&PageSize=${this.PageSize}&username=${this.username}`)
        console.log(res.data)
        this.tableData=res.data
        this.total=res.total
      },
      changesize(val){
        this.PageSize=val
        this.getAll()
      },
      changenum(val){
        this.PageNum=val
        this.getAll()
      },
     async handlDelete(val){
        const res = await this.$axios.delete(`User/DeleteUser/${val}`)
        console.log(res)
        this.$message.success(res.msg)
        this.getAll()
      },
      async handlEditor(val){
        const res = await this.$axios.get(`User/SelectById/${val}`)
        console.log(res)
        this.changeTitle('编辑')
        this.changeDatas(res)
        this.$router.push("/adduser")

      },
      add(){
        this.changeTitle('添加')
        this.$router.push("/adduser")
      },
      async handlget(){
        this.getAll()
      },
    }
}
</script>

<style scoped lang="less">
.header-Main{
  margin-bottom: 10px;
}

.iconadd{
  display: inline-block;
  font-size: 5px;
  padding-left: 5px;
}

.pageion{
  display: flex;
  margin-top: 30px;
  justify-content: center;
}
::v-deep .el-table th{
    text-align: center;
  }
  ::v-deep .el-table td, .el-table th {
    text-align: center;
  }

  .imagecontainer{
    height: 120px;
    width: 120px;
  }
</style>